import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'dart:ui' as ui;
/*
* 类似 二维码提醒框
*
*/
typedef onCloseEvent = void Function();
class PublicQRToast extends Dialog {
  onCloseEvent closeCallBack;
  String nameTip;
  String phoneTip;
  String validDateTip;
  String title;
  String cancelText;
  String messageUrl;
  PublicQRToast({
    this.cancelText,
    this.title,
    this.nameTip,
    this.phoneTip,
    this.validDateTip,
    this.messageUrl="",
    @required this.closeCallBack,
  });

  Widget MainComponent(){
    return Stack(
      children: [
        Opacity(
          opacity: 0.46,
          child:Container(
            color: Color(0xff101010),
            width: ScreenUtil.screenWidth,
            height: ScreenUtil.screenHeight,
          ) ,
        ),
        Positioned(
            top: ScreenUtil().setWidth(250),
            left: ScreenUtil().setWidth(503),
            child: CenterWidget()
        ),
      ],
    );
  }
  //中间视图背景
  Widget CenterBG(){
    return Container(
      decoration: ShapeDecoration(
        color: Color(0xffffffff),
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.all(
            Radius.circular(11.2),
          ),
        ),
      ),
      width:ScreenUtil().setWidth(752) ,
      height: ScreenUtil().setWidth(484),
    );
  }
  //中间视图
  Widget CenterWidget(){
    return Stack(
        children: <Widget>[
          CenterBG(),
          Positioned(
            left: ScreenUtil().setWidth(0),
            top: ScreenUtil().setWidth(0),
            child: Container(
              width: ScreenUtil().setWidth(752),
              height: ScreenUtil().setWidth(64),
              decoration: ShapeDecoration(
                color: Color(0xffF6F5F7),
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(11.2),
                    topRight: Radius.circular(11.2),
                  ),
                ),
              ),
              child:Row(
                children: [
                  SizedBox(width:ScreenUtil().setWidth(85),),
                  Column(
                    children: [
                      SizedBox(height: ScreenUtil().setWidth(12.5),),
                      Text(title??"微信公众号营销二维码", style: TextStyle(color: Color(0xff000000), fontFamily: 'PingFangSC-Medium',fontSize:ScreenUtil().setSp(26)),textAlign: TextAlign.center,),
                    ],
                  )
                ],
              ),
            ),
          ),
          Positioned(
              left: 0,
              top: ScreenUtil().setWidth(64),
              child: Container(
                width: ScreenUtil().setWidth(752),
                height: ScreenUtil().setWidth(406),
                child: Column(
                  children: [
                    SizedBox(width: 1,height: ScreenUtil().setWidth(41)),
                    Row(
                      children: [
                        SizedBox(width:ScreenUtil().setWidth(85),height: 1,),
                        CustomPaint(
                              size: Size.square(ScreenUtil().setWidth(159)),
                               painter: QrPainter(
                               data: this.messageUrl,
                               version: QrVersions.auto,
                             ),
                         ),
                        // Image.asset('sources/qR.png',width: ScreenUtil().setWidth(179),height: ScreenUtil().setWidth(179),),
                        SizedBox(width:ScreenUtil().setWidth(79),height: 1,),
                        Column(
                          children: [
                            SizedBox(height: ScreenUtil().setWidth(11),),
                            RowLabelGroup('客户经理:', nameTip??"", 110, 244),
                            SizedBox(height: ScreenUtil().setWidth(19),),
                            RowLabelGroup('联系电话:', phoneTip??"", 110, 244),
                            SizedBox(height: ScreenUtil().setWidth(20),),
                            RowLabelGroup('有效期:', validDateTip??"", 110,244 ),
                          ],
                        ),
                      ],
                    ),

                  ],
                ),
              )
          ),
          Positioned(
            left: ScreenUtil().setWidth(0),
            top: ScreenUtil().setWidth(353),
            child: Container(
              width: ScreenUtil().setWidth(752),
              height: ScreenUtil().setWidth(1),
              color: Color(0xffE4E3E3),
            ),
          ),

          Positioned(
            child: InkWell(
                onTap:(){
                  this.closeCallBack();
                },
                child: Container(
                  width: ScreenUtil().setWidth(260),
                  height: ScreenUtil().setWidth(60),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(30),
                    color:Color(0xffF22A02),
                  ),
                  child: new Center(
                    child:new Text(cancelText??"关闭",style: TextStyle(fontFamily:"PingFangSC-Regular", fontSize: ScreenUtil().setSp(24),color: Color(0xffFFFFFF)),textAlign: TextAlign.center,),
                  ),
                )
            ),
            left: ScreenUtil().setWidth(249),
            top: ScreenUtil().setWidth(391),
          ),
        ]
    );
  }
  //左右排列标签
  Widget RowLabelGroup(String leftTitle,String rightTitle ,double leftWidth,double rightWidth){
    return Row(
      children: <Widget>[
        Container(
          width: ScreenUtil().setWidth(leftWidth),
          child: Text(leftTitle ,style: TextStyle(fontSize: ScreenUtil().setSp(24),color: Color(0xff454545),height: 1.1,),),
        ),
        Container(
          width: ScreenUtil().setWidth(rightWidth),
          child: Text(rightTitle ,style: TextStyle(fontSize: ScreenUtil().setSp(24),height: 1.1,color: Color(0xff454545)),overflow: TextOverflow.ellipsis,maxLines: 2,),
        )
      ],
    );
  }
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 1600, height: 900, allowFontScaling: true);
    return new Material(
        type: MaterialType.transparency,
        child: new Center(
          child: CenterWidget(),
        )
    );
  }
}



